package study.springcloud.client.feign.support.interceptor;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;

/**
 * 可以在构造 RequestTemplate 请求时，增加或者修改Header, Method, Body等信息
 */
@Slf4j
public class GlobalRequestInterceptor implements RequestInterceptor {

    @Autowired
    private LoadBalancerFeignClient loadBalancerFeignClient;

    @Override
    public void apply(RequestTemplate request) {
        log.info(">>>>>>>>>> Global Request Interceptor");
        //
        String url = request.url();
        String method = request.method();
        log.info(">>>>>>>>>> url= {}", url);
        //header
        request.header("name", "wangzhenjun");
        //param
        request.query("name", "666666");
    }
}
